# $Id: Makefile.am 5 2008-05-27 10:41:12Z lafriks $

macrosfiles = $(RPMALLARCH:=.macros)

pkg_data = \
		   rpmpopt

pkg_gdata = \
		   rpmrc \
		   macros

pkg_data_in = $(pkg_gdata:=.in)

pkg_gconfig = \
		   platform \
		   $(if $(CANONTARGETCPU32), platform32, )

pkg_scripts = \
		brp-compress \
		brp-strip \
		brp-strip-comment-note \
		brp-strip-static-archive \
		filter.sh \
		find-lang.pl \
		kill-lang.sh \
		find-debuginfo.sh \
		http.req \
		magic.prov \
		magic.req \
		kmod.prov \
		perl.prov \
		perl.req \
		php.prov \
		php.req \
		pkgconfigdeps.sh

pkg_gscripts = \
		find-provides \
		find-requires \
		find-provides.perl

pkg_scripts_in = $(pkg_gscripts:=.in)

BUILT_SOURCES = macros-perarch make_macrosfiles.sh rpmgenplatform

pkglibdir = @RPMVENDORDIR@

noinst_PROGRAMS = rpmeval

rpmeval_SOURCES = rpmeval.c

rpmeval_LDFLAGS = -lrpm

noinst_DATA = $(pkg_gconfig)

pkglib_DATA = \
	$(pkg_data) \
	$(pkg_gdata)
	$(pkg_gconfig)

pkglib_SCRIPTS = \
	$(pkg_scripts) \
	$(pkg_gscripts)

EXTRA_DIST = \
	$(pkg_data) \
	$(pkg_data_in) \
	$(pkg_scripts) \
	$(pkg_scripts_in) \
	macros-perarch.in make_macrosfiles.sh.in \
	rpmgenplatform.in \
	rpm-spec-mode.el \
	tests.sh tests/macros.sh \
	tests/findlang.pl tests/findlang.sh

edit = sed \
	-e 's,@RPMVENDOR\@,$(RPMVENDOR),g' \
	-e 's,@RPMVENDORDIR\@,$(RPMVENDORDIR),g' \
	-e 's,@RPMCANONVENDOR\@,$(RPMCANONVENDOR),g' \
	-e 's,@RPMLIBDIR\@,$(RPMLIBDIR),g' \
	-e 's,@RPMSYSCONFDIR\@,$(RPMSYSCONFDIR),g'\
	-e 's,@RPMOS\@,$(RPMOS),g' \
	-e 's,@CANONTARGETCPU\@,$(CANONTARGETCPU),g' \
	-e 's,@RPMALLARCH\@,$(RPMALLARCH),g' 

%: %.in Makefile
	$(edit) $< > $@

%.macros: macros-perarch make_macrosfiles.sh
	arch=`echo $@ | sed 's,\\.macros,,'`; \
	sh ./make_macrosfiles.sh macros-perarch $$arch > $@

platform: rpmgenplatform Makefile
	perl rpmgenplatform $(CANONTARGETCPU) > $@

platform32: rpmgenplatform Makefile
	perl rpmgenplatform $(CANONTARGETCPU32) > $@

install-data-local: $(macrosfiles) $(pkg_gconfig)
	for i in $(RPMALLARCH); do \
	  $(mkinstalldirs) $(DESTDIR)$(RPMVENDORDIR)/$${i}-$(RPMOS); \
	  $(install_sh_DATA) $${i}.macros $(DESTDIR)$(RPMVENDORDIR)/$${i}-$(RPMOS)/macros; \
	done
	[ -d $(DESTDIR)$(RPMSYSCONFDIR) ] || $(mkinstalldirs) $(DESTDIR)$(RPMSYSCONFDIR)
	for i in $(pkg_gconfig); do \
		$(install_sh_DATA) $${i} $(DESTDIR)$(RPMSYSCONFDIR)/$${i}; \
	done
	$(install_sh_SCRIPT) rpmgenplatform $(DESTDIR)$(bindir)/rpmgenplatform

.PHONY: ChangeLog test

ChangeLog:
	LC_ALL=C svn2cl
	rm -f *.bak

test: $(pkg_gdata) $(pkg_gscripts) $(macrosfiles) $(pkg_gconfig)
	sh tests.sh

CLEANFILES = $(pkg_gdata) $(pkg_gscripts) $(macrosfiles) $(pkg_gconfig)\
			 macros-perarch \
			 make_macrosfiles.sh
